#ifndef MESSAGEMODEL_H
#define MESSAGEMODEL_H

#include "../../global/xnamespace.h"

#include <QDateTime>

X_BEGIN_NAMESPACE

// Private data，需要放到CPP文件中
class MessageModelPrivate : public QSharedData {
public:
    MessageModelPrivate();
    MessageModelPrivate(const MessageModelPrivate& src);

    int m_id;
    QString m_content;
    QString m_thumbnail;
    QString m_senderJid;
    QString m_senderName;
    QString m_senderPhoto;
    QDateTime m_time;
    MessageContentType m_contentType;
};

// 消息模型
class MessageModel : public QObject
{
    Q_OBJECT

    Q_PROPERTY(int id READ id NOTIFY idChanged)
    Q_PROPERTY(QString content READ content NOTIFY contentChanged)
    Q_PROPERTY(X::MessageContentType contentType READ contentType NOTIFY contentTypeChanged)
    Q_PROPERTY(QString senderJid READ senderJid NOTIFY senderJidChanged)
    Q_PROPERTY(QString senderName READ senderName NOTIFY senderNameChanged)
    Q_PROPERTY(QString senderPhoto READ senderPhoto WRITE setSenderPhoto NOTIFY senderPhotoChanged)
    Q_PROPERTY(QDateTime time READ time NOTIFY timeChanged)
    Q_PROPERTY(QString thumbnail READ thumbnail NOTIFY thumbnailChanged)

signals:
    void idChanged(int id);
    void contentChanged(QString content);
    void contentTypeChanged(MessageContentType contentType);
    void senderJidChanged(QString senderJid);
    void senderNameChanged(QString senderName);
    void senderPhotoChanged(QString senderPhoto);
    void timeChanged(QDateTime time);
    void thumbnailChanged(QString thumbnail);

public:
    MessageModel();
    MessageModel(int id);
    MessageModel(const MessageModel& src);
    MessageModel &operator =(const MessageModel& rhs);

    static const char *qmlName();

public:
    int id() const;
    QString content() const;
    QString thumbnail() const;
    QString senderJid() const;
    QString senderName() const;
    QString senderPhoto() const;
    QDateTime time() const;
    MessageContentType contentType() const;

public slots:
    MessageModel &setContent(QString content);
    MessageModel &setThumbnail(QString thumbnail);
    MessageModel &setContentType(MessageContentType contentType);
    MessageModel &setSenderJid(QString senderJid);
    MessageModel &setSenderName(QString senderName);
    MessageModel &setSenderPhoto(QString senderPhoto);
    MessageModel &setTime(QDateTime time);

private:
    QSharedDataPointer<MessageModelPrivate> d;
};

X_END_NAMESPACE

#endif // MESSAGEMODEL_H
